package com.pmcc.core.config.security;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * jwt 验证需要用到的全局的用户信息
 */
public class JwtUser implements UserDetails {

    private final String id;//用户id
    private final String username;//用户名
    private final String password;//密码
    private final String email;//邮箱
    private final String role;//角色
    private final Collection<? extends GrantedAuthority> authorities;//权限
    private final boolean enabled;//启用禁用
    private final Date lastPasswordResetDate;//最后一次重置密码日期
    private final String name;//用户姓名

    public JwtUser(
          String id,
          String username,
          String email,
          String role,
          String password,
          Collection<? extends GrantedAuthority> authorities,
          boolean enabled,
          Date lastPasswordResetDate,
          String name
    ) {
        this.id = id;
        this.username = username;
        this.email = email;
        this.password = password;
        this.role=role;
        this.authorities = authorities;
        this.enabled = enabled;
        this.lastPasswordResetDate = lastPasswordResetDate;
        this.name=name;
    }

    @JsonIgnore
    public String getId() {
        return id;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }



    public String getEmail() {
        return email;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return password;
    }


    @Override
    public boolean isEnabled() {
        return enabled;
    }

    @JsonIgnore
    public Date getLastPasswordResetDate() {
        return lastPasswordResetDate;
    }

    @JsonIgnore
    public String getRole() {
        return role;
    }

    public String getName() {
        return name;
    }
}
